// 
// 
// 

#include "Controller.h"

void Controller::init()
{
	gestureService.registerListener([this](Event& evt) {
		whenGestureUpdate((GestureEvent&) evt);
	});
}

void Controller::suspend()
{
	this->isSuspend = true;
}

void Controller::active()
{
	this->isSuspend = false;
}

void Controller::whenGestureUpdate(GestureEvent& evt)
{
	if (isSuspend) { return; }
	
	Gesture gesture = evt.gesture;
    if (gesture & GES_UP) {
		Serial.println("GES_UP");
        whenGestureUp();
    }
    if (gesture & GES_DOWN) {
		Serial.println("GES_DOWN");
        whenGestureDown();
    }
    if (gesture & GES_LEFT) {
		Serial.println("GES_LEFT");
        whenGestureLeft();
    }
    if (gesture & GES_RIGHT) {
		Serial.println("GES_RIGHT");
        whenGestureRight();
    }
    if (gesture & GES_FORWARD) {
		Serial.println("GES_FORWARD");
        whenGestureForward();
    }
    if (gesture & GES_BACKWARD) {
		Serial.println("GES_BACKWARD");
        whenGestureBackward();
    }
    if (gesture & GES_CLOCKWISE) {
		Serial.println("GES_CLOCKWISE");
        whenGestureClockwise();
    }
    if (gesture & GES_COUNT_CLOCKWISE) {
		Serial.println("GES_COUNT_CLOCKWISE");
        whenGestureCounterClockwise();
    }
}

